package com.xbk.seckill.common.builder;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.xbk.seckill.common.cache.model.SeckillBusinessCache;

import java.util.List;
import java.util.Objects;

/**
 * @author xiexu
 * @date 2025/2/4 11:05
 */
public class SeckillCommonBuilder {

    /**
     * Json泛型化处理
     */
    public static <T> SeckillBusinessCache<T> getSeckillBusinessCache(Object object, Class<T> clazz) {
        if (Objects.isNull(object)) {
            return null;
        }
        return JSON.parseObject(object.toString(), new TypeReference<SeckillBusinessCache<T>>(clazz) {
        });
    }

    /**
     * Json泛型化处理
     */
    public static <T> SeckillBusinessCache<List<T>> getSeckillBusinessCacheList(Object object, Class<T> clazz) {
        if (Objects.isNull(object)) {
            return null;
        }
        return JSON.parseObject(object.toString(), new TypeReference<SeckillBusinessCache<List<T>>>(clazz) {
        });
    }

}
